<?PHP

require_once('lib/webservices/api/studip_android.php');

class AndroidService extends Studip_Ws_Service {

	function __construct() {
		$this->add_api_method(
			'get_notifications', 
			array('string', 'string', 'string'),
			array('string'),
			'returns details for specific schedule');

		$this->add_api_method(
			'get_feed', 
			array('string', 'string', 'string'),
			array('string'),
			'returns last changes for user');

		$this->add_api_method(
			'has_news_authorization', 
			array('string', 'string', 'string'),
			array('string'),
			'returns if a user may access a news article');

		$this->add_api_method(
			'get_news', 
			array('string', 'string', 'string'),
			array('string'),
			'returns details for specific news');

		$this->add_api_method(
			'has_message_authorization', 
			array('string', 'string', 'string'),
			array('string'),
			'returns if a user may access a message');

		$this->add_api_method(
			'get_message', 
			array('string', 'string'),
			array('string'),
			'returns details for specific message');

		$this->add_api_method(
			'has_schedule_authorization', 
			array('string', 'string', 'string'),
			array('string'),
			'returns if a user may access a schedule entry');

		$this->add_api_method(
			'get_schedule', 
			array('string', 'string'),
			array('string'),
			'returns details for specific schedule');

		$this->add_api_method(
			'has_seminar_authorization', 
			array('string', 'string', 'string'),
			array('string'),
			'returns if a user may access a seminar');

		$this->add_api_method(
			'get_seminar_details', 
			array('string', 'string'),
			array('string'),
			'returns details for specific seminar');

		$this->add_api_method(
			'set_object_visited', 
			array('string', 'string', 'string', 'string'),
			array('string'),
			'marks message as read by user');

		$this->add_api_method(
			'send_message', 
			array('string', 'string', 'string', 'string', 'string'),
			array('string'),
			'sends a message');

		$this->add_api_method(
			'search_person', 
			array('string', 'string'),
			array('string'),
			'sends a message');

		$this->add_api_method(
			'get_user_seminars', 
			array('string', 'string'),
			array('string'),
			'get all seminars for a user');
			
		$this->add_api_method(
			'get_seminar_participants', 
			array('string', 'string'),
			array('string'),
			'get all participants for a seminar');
			
		$this->add_api_method(
			'get_incoming_messages', 
			array('string', 'string', 'string'),
			array('string'),
			'get all participants for a seminar');
			
		$this->add_api_method(
			'export_schedule', 
			array('string', 'string', 'string'),
			array('string'),
			'get schedule entries for user');
			
		$this->add_api_method(
			'get_visited_objects_since', 
			array('string', 'string', 'string'),
			array('string'),
			'get ids of all objects that were visited since spefified moment.');
			
			$this->add_api_method('check_credentials',
                        array('string', 'string', 'string'),
                        array('string'),
                        'returns a token for user if credentials are valid');

	}

	function get_notifications_action($api_key, $username, $since)
	{
		return Android::getNotifications(get_userid($username), $since);
	}

	function get_feed_action($api_key, $username, $since) 
	{
		return Android::getFeed(get_userid($username), $since);
	}

	function has_news_authorization_action($api_key, $username, $news_id)
	{
		return Android::hasNewsAuthorization(get_userid($username), $news_id);
	}
	
	function get_news_action($api_key, $news_id) 
	{
		return Android::getNews($news_id);
	}

	function has_message_authorization_action($api_key, $username, $message_id)
	{
		return Android::hasMessageAuthorization(get_userid($username), $message_id);
	}
	
	function get_message_action($api_key, $message_id)//, $username)
	{
		return Android::getMessage($message_id);//, get_userid($username));
	}

	function has_schedule_authorization_action($api_key, $username, $schedule_id)
	{
		return Android::hasScheduleAuthorization(get_userid($username), $schedule_id);
	}
	
	function get_schedule_action($api_key, $schedule_id)
	{
		return Android::getSchedule($schedule_id);
	}

	function has_seminar_authorization_action($api_key, $username, $seminar_id)
	{
		return Android::hasSeminarAuthorization(get_userid($username), $seminar_id);
	}
	
	function get_seminar_details_action($api_key, $seminar_id)
	{
		return Android::getSeminarDetails($seminar_id);
	}

	function set_object_visited_action($api_key, $object_id, $type, $username)
	{
		return Android::setObjectVisited($object_id, $type, get_userid($username));
	}

	function send_message_action($api_key, $username, $rec_uname, $subject, $text)
	{
		return Android::sendMessage(get_userid($username), $rec_uname, $subject, $text);
	}

	function search_person_action($api_key, $expression)
	{
		return Android::searchPerson($expression);
	}
	
	function get_user_seminars_action($api_key, $username)
	{
		return Android::getUserSeminars(get_userid($username));
	}
	
	function get_seminar_participants_action($api_key, $seminar_id)
	{
		return Android::getSeminarParticipants($seminar_id);
	}
	
	function get_incoming_messages_action($api_key, $username, $since)
	{
		return Android::getIncomingMessages(get_userid($username), $since);
	}
	
	function export_schedule_action($api_key, $username, $since)
	{
		return Android::exportSchedule(get_userid($username), $since);
	}
	
	function get_visited_objects_since_action($api_key, $username, $since)
	{
		return Android::getVisitedObjectsSince(get_userid($username), $since);
	}

	function check_credentials_action($api_key, $username, $password) {

		$result = Android::checkCredentials($username, $password);

		if ($result['uid'] != false)
		{
			$token = new Token($result['uid']);

			return $token->get_string();
		} else
		{
			return null;
		}
	}
}
